import { DialogForm } from 'custom/index'
import SkList from '../components/SkList.vue'
import TkList from '../components/TkList.vue'
import XfList from '../components/XfList.vue'
import FpList from '../components/FpList.vue'

import { getRenewShouList, postSkList, getRenewTuiList, postTkList, getXfywListBySfmsValAndCustomerId, postXfList, getFpListByCustomerId } from '../api'

const addSkDialog = new DialogForm('DialogForm')
const addTkDialog = new DialogForm('DialogForm')
const addXfDialog = new DialogForm('DialogForm')
const addFpDialog = new DialogForm('DialogForm')

addSkDialog
    .title('收款')
    .width('90%')
    .getApi(async (_, row) => {
        const res = await getRenewShouList({ batchId: row.batchId });
        row.skList = res;
        return row;
    })
    .postApi(postSkList)
    .useGroup('收费记录')
    .useCustomItem(SkList, 'skList').end()

addTkDialog
    .title('退款')
    .width('80%')
    .getApi(async (_, row) => {
        const res = await getRenewTuiList({ batchId: row.batchId });
        row.tkList = res;
        return row;
    })
    .postApi(postTkList)
    .useGroup('退费记录')
    .useCustomItem(TkList, 'tkList').end()

addXfDialog
    .title('续费')
    .width('95%')
    .getApi(async (_, row) => {
        const res = await getXfywListBySfmsValAndCustomerId({ sfmsVal: row.sfmsVal, customerId: row.customerId });
        console.log(res);
        row.xfList = res;
        if (res.length) {
            row.ywkssj = res[0].ywkssj;
            row.ywjssj = res[0].ywjssj;
            row.sfmsVal = res[0].sfmsVal;
        }
        console.log(row);
        return row;
    }).postApi(async (row) => {
        console.log(row);
        return postXfList(row);
    })
    .useGroup('续费信息')
    .useCustomItem(XfList, 'xfList').end()


addFpDialog.title('添加发票')
    .getApi(async (_, row) => {
        const res = await getFpListByCustomerId({ customerId: row.customerId });
        row.fpList = res;
        return row;
    }).useGroup('发票信息')
    .useCustomItem(FpList, 'fpList').end()

export { addSkDialog, addTkDialog, addXfDialog, addFpDialog }